package com.rr.hippo4jdemo.service.impl;

import com.rr.hippo4jdemo.service.DynamicSyncService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author RR
 * @date 2024/7/20 21:32
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class DynamicSyncServiceImpl implements DynamicSyncService {

    private final ThreadPoolExecutor dynamicThreadPoolExecutor;

    @Override
    public void doSync() {
        dynamicThreadPoolExecutor.execute(()->{
            log.info("异步执行开始...thread:{}", Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.info("异步执行结束...thread:{}", Thread.currentThread().getName());
        });
    }
}
